
// tutorial: https://minstrel1977.gitee.io/rust-reference/types/closure.html

use std::collections::HashSet;

#[allow(unused)]
struct SetVec {
    set: HashSet<u32>,
    vec: Vec<u32>,
}

#[allow(unused)]
impl SetVec {
    fn populate(&mut self) {
        let vec = &mut self.vec;
        self.set.iter().for_each(|&n| {
            vec.push(n);
        })
    }
}


fn f<F: FnOnce() -> String> (g: F) {
    println!("{}", g());
}

fn main() {
    println!("闭包：");

    {
        let mut s = String::from("foo");
        let t = String::from("bar");

        f (|| {
            s += &t;
            s
        });
    }

}